
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>svg 描边动画 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../svg之fill及fill-rule/svg之fill及fill-rule.html" />
    
    
    <link rel="prev" href="../svg之path/svg之path.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../svg基础/svg基础.html">
            
                <a href="../svg基础/svg基础.html">
            
                    
                    svg 基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../svg基本图形/svg基本图形.html">
            
                <a href="../svg基本图形/svg基本图形.html">
            
                    
                    svg 基本图形
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../svg之path/svg之path.html">
            
                <a href="../svg之path/svg之path.html">
            
                    
                    svg 之 path
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5" data-path="svg描边动画.html">
            
                <a href="svg描边动画.html">
            
                    
                    svg 描边动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../svg之fill及fill-rule/svg之fill及fill-rule.html">
            
                <a href="../svg之fill及fill-rule/svg之fill及fill-rule.html">
            
                    
                    svg 之 fill 及 fill-rule
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../svg之viewBox/svg之viewBox.html">
            
                <a href="../svg之viewBox/svg之viewBox.html">
            
                    
                    svg 之 viewBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../svg分组与复用/svg分组与复用.html">
            
                <a href="../svg分组与复用/svg分组与复用.html">
            
                    
                    svg 分组与复用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../svg之marker/svg之marker.html">
            
                <a href="../svg之marker/svg之marker.html">
            
                    
                    svg 之 marker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../svg文本/svg文本.html">
            
                <a href="../svg文本/svg文本.html">
            
                    
                    svg 文本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../svg之pattern/svg之pattern.html">
            
                <a href="../svg之pattern/svg之pattern.html">
            
                    
                    svg 之 pattern
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../svg之clipPath和mask/svg之clipPath和mask.html">
            
                <a href="../svg之clipPath和mask/svg之clipPath和mask.html">
            
                    
                    svg 之 clipPath 和 mask
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../svg之filter/svg之filter.html">
            
                <a href="../svg之filter/svg之filter.html">
            
                    
                    svg 之 filter
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >svg 描边动画</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="svg-&#x63CF;&#x8FB9;&#x52A8;&#x753B;">svg &#x63CF;&#x8FB9;&#x52A8;&#x753B;</h1>
<p>&#x5728;&#x5F00;&#x59CB;&#x8BB2;&#x89E3;&#x4E4B;&#x524D;&#xFF0C;&#x5148;&#x6765;&#x770B;&#x770B;&#x6548;&#x679C;</p>
<p><img src="https://raw.githubusercontent.com/zhansingsong/svg-tutorials/master/svg%E6%8F%8F%E8%BE%B9%E5%8A%A8%E7%94%BB/imgs/svg.gif" alt="svg"></p>
<h2 id="svg-&#x63CF;&#x8FB9;&#x5C5E;&#x6027;-stroke">svg &#x63CF;&#x8FB9;&#x5C5E;&#x6027; stroke</h2>
<p>&#x5728; svg &#x4E2D;&#x5BF9;&#x56FE;&#x5F62;&#xFF08;line&#x3001;polyline&#x3001;rect&#x3001;circle&#x3001;ellipse&#x3001;polygon&#xFF09;&#x3001;&#x8DEF;&#x5F84;&#xFF08;path&#xFF09;&#x3001;&#x6587;&#x672C;(text&#x3001;textPath&#x3001;tspan)&#x7684;&#x63CF;&#x8FB9;&#x90FD;&#x9700;&#x8981;&#x7528;&#x5230;<code>stroke</code>&#x5C5E;&#x6027;&#x3002;</p>
<h3 id="stroke-&#x5E38;&#x7528;&#x5C5E;&#x6027;">stroke &#x5E38;&#x7528;&#x5C5E;&#x6027;</h3>
<ul>
<li><p>stroke&#xFF1A;&#x989C;&#x8272;&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">svg</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://www.w3.org/2000/svg&quot;</span> <span class="hljs-attr">version</span>=<span class="hljs-string">&quot;1.1&quot;</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">g</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;red&quot;</span> <span class="hljs-attr">d</span>=<span class="hljs-string">&quot;M0 20 l200 0&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;green&quot;</span> <span class="hljs-attr">d</span>=<span class="hljs-string">&quot;M0 40 l200 0&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;blue&quot;</span> <span class="hljs-attr">d</span>=<span class="hljs-string">&quot;M0 60 l200 0&quot;</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
</code></pre>
<p><img src="https://raw.githubusercontent.com/zhansingsong/svg-tutorials/master/svg%E6%8F%8F%E8%BE%B9%E5%8A%A8%E7%94%BB/imgs/stroke.png" alt="stroke"></p>
</li>
<li><p>stroke-width&#xFF1A;&#x5BBD;&#x5EA6;&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">svg</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://www.w3.org/2000/svg&quot;</span> <span class="hljs-attr">version</span>=<span class="hljs-string">&quot;1.1&quot;</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">g</span> <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;black&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">stroke-width</span>=<span class="hljs-string">&quot;2&quot;</span> <span class="hljs-attr">d</span>=<span class="hljs-string">&quot;M0 20 l200 0&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">stroke-width</span>=<span class="hljs-string">&quot;6&quot;</span> <span class="hljs-attr">d</span>=<span class="hljs-string">&quot;M0 40 l200 0&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">stroke-width</span>=<span class="hljs-string">&quot;12&quot;</span> <span class="hljs-attr">d</span>=<span class="hljs-string">&quot;M0 60 l200 0&quot;</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
</code></pre>
<p><img src="https://raw.githubusercontent.com/zhansingsong/svg-tutorials/master/svg%E6%8F%8F%E8%BE%B9%E5%8A%A8%E7%94%BB/imgs/stroke-width.png" alt="stroke-width"></p>
</li>
<li><p>stroke-linecap&#xFF1A;&#x7EBF;&#x7AEF;&#x70B9;&#x6837;&#x5F0F;&#x3002;&#x53D6;&#x503C;<code>butt</code>&#x3001;<code>round</code>&#x3001;<code>square</code>&#xFF0C;&#x9ED8;&#x8BA4;<code>butt</code>&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">svg</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://www.w3.org/2000/svg&quot;</span> <span class="hljs-attr">version</span>=<span class="hljs-string">&quot;1.1&quot;</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">g</span> <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;black&quot;</span> <span class="hljs-attr">stroke-width</span>=<span class="hljs-string">&quot;6&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">stroke-linecap</span>=<span class="hljs-string">&quot;butt&quot;</span> <span class="hljs-attr">d</span>=<span class="hljs-string">&quot;M10 20 l210 0&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">stroke-linecap</span>=<span class="hljs-string">&quot;round&quot;</span> <span class="hljs-attr">d</span>=<span class="hljs-string">&quot;M10 40 l210 0&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">stroke-linecap</span>=<span class="hljs-string">&quot;square&quot;</span> <span class="hljs-attr">d</span>=<span class="hljs-string">&quot;M10 60 l210 0&quot;</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
</code></pre>
<p><img src="https://raw.githubusercontent.com/zhansingsong/svg-tutorials/master/svg%E6%8F%8F%E8%BE%B9%E5%8A%A8%E7%94%BB/imgs/stroke-linecap.png" alt="stroke-linecap"></p>
</li>
<li><p>stroke-opacity&#xFF1A;&#x900F;&#x660E;&#x5EA6;&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">svg</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://www.w3.org/2000/svg&quot;</span> <span class="hljs-attr">version</span>=<span class="hljs-string">&quot;1.1&quot;</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">g</span> <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;black&quot;</span> <span class="hljs-attr">stroke-width</span>=<span class="hljs-string">&quot;6&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">stroke-opacity</span>=<span class="hljs-string">&quot;0.2&quot;</span> <span class="hljs-attr">d</span>=<span class="hljs-string">&quot;M10 20 l210 0&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">stroke-opacity</span>=<span class="hljs-string">&quot;0.6&quot;</span> <span class="hljs-attr">d</span>=<span class="hljs-string">&quot;M10 40 l210 0&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">stroke-opacity</span>=<span class="hljs-string">&quot;1&quot;</span> <span class="hljs-attr">d</span>=<span class="hljs-string">&quot;M10 60 l210 0&quot;</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
</code></pre>
<p><img src="https://raw.githubusercontent.com/zhansingsong/svg-tutorials/master/svg%E6%8F%8F%E8%BE%B9%E5%8A%A8%E7%94%BB/imgs/stroke-opacity.png" alt="stroke-opacity"></p>
</li>
<li><p>stroke-linejoin&#xFF1A;&#x8F6C;&#x89D2;&#x5904;&#x6837;&#x5F0F;&#x3002;&#x53D6;&#x503C;<code>arcs</code>&#x3001;<code>bevel</code>&#x3001;<code>miter</code>&#x3001;<code>round</code>&#xFF0C;&#x9ED8;&#x8BA4;<code>miter</code>&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">svg</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://www.w3.org/2000/svg&quot;</span> <span class="hljs-attr">version</span>=<span class="hljs-string">&quot;1.1&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;400&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;300&quot;</span>
   <span class="hljs-attr">viewBox</span>=<span class="hljs-string">&quot;0 0 400 300&quot;</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">g</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">polyline</span> <span class="hljs-attr">stroke-linejoin</span>=<span class="hljs-string">&quot;miter&quot;</span>
              <span class="hljs-attr">points</span>=<span class="hljs-string">&quot;20,100 60,30 100,100&quot;</span>
              <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;black&quot;</span> <span class="hljs-attr">stroke-width</span>=<span class="hljs-string">&quot;30&quot;</span>
              <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;none&quot;</span> /&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">polyline</span> <span class="hljs-attr">stroke-linejoin</span>=<span class="hljs-string">&quot;round&quot;</span>
              <span class="hljs-attr">points</span>=<span class="hljs-string">&quot;20,180 60,110 100,180&quot;</span>
              <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;black&quot;</span> <span class="hljs-attr">stroke-width</span>=<span class="hljs-string">&quot;30&quot;</span>
              <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;none&quot;</span> /&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">polyline</span> <span class="hljs-attr">stroke-linejoin</span>=<span class="hljs-string">&quot;bevel&quot;</span>
              <span class="hljs-attr">points</span>=<span class="hljs-string">&quot;20,260 60,190 100,260&quot;</span>
              <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;black&quot;</span> <span class="hljs-attr">stroke-width</span>=<span class="hljs-string">&quot;30&quot;</span>
              <span class="hljs-attr">fill</span>=<span class="hljs-string">&quot;none&quot;</span> /&gt;</span>

  <span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
</code></pre>
<p><img src="https://raw.githubusercontent.com/zhansingsong/svg-tutorials/master/svg%E6%8F%8F%E8%BE%B9%E5%8A%A8%E7%94%BB/imgs/stroke-linejoin.png" alt="stroke-linejoin"></p>
</li>
<li><p>stroke-dasharray&#xFF1A;&#x5B9A;&#x4E49;&#x865A;&#x7EBF;&#x6837;&#x5F0F;&#x3002;&#x53D6;&#x503C;&#x662F;&#x4E00;&#x4E2A;&#x9017;&#x53F7;&#x6216;&#x8005;&#x7A7A;&#x683C;&#x5206;&#x9694;&#x7684;&#x6570;&#x5217;&#x3002;&#x6570;&#x5217;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x503C;&#x8868;&#x793A;dash&#x5927;&#x5C0F;&#x3001;&#x7B2C;&#x4E8C;&#x503C;&#x8868;&#x793A;&#x4E24;&#x4E2A;dash&#x4E4B;&#x95F4;&#x7A7A;&#x9699;&#x5927;&#x5C0F;&#x3002;&#x5982;<code>stroke-dasharray:10, 2</code> &#x8868;&#x793A;dash&#x5927;&#x5C0F;10&#x3001;dash&#x95F4;&#x9699;2&#x3002;&#x5982;&#x679C;&#x63D0;&#x4F9B;&#x6570;&#x5217;&#x662F;&#x5947;&#x6570;&#x4E2A;&#xFF0C;&#x5219;&#x4F1A;&#x91CD;&#x590D;&#x4E00;&#x6B21;&#x5F62;&#x6210;&#x5076;&#x6570;&#x4E2A;&#x3002;&#x5982;<code>stroke-dasharray:10</code>&#x7B49;&#x6548;&#x4E8E;<code>stroke-dasharray:10, 10</code>&#x6216;<code>stroke-dasharray:10, 2, 5</code>&#x7B49;&#x6548;&#x4E8E;<code>stroke-dasharray:10, 2, 5, 10, 2, 5</code>&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">svg</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://www.w3.org/2000/svg&quot;</span> <span class="hljs-attr">version</span>=<span class="hljs-string">&quot;1.1&quot;</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">g</span> <span class="hljs-attr">stroke</span>=<span class="hljs-string">&quot;black&quot;</span> <span class="hljs-attr">stroke-width</span>=<span class="hljs-string">&quot;6&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">stroke-dasharray</span>=<span class="hljs-string">&quot;5,5&quot;</span> <span class="hljs-attr">d</span>=<span class="hljs-string">&quot;M10 20 l210 0&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">stroke-dasharray</span>=<span class="hljs-string">&quot;10,10&quot;</span> <span class="hljs-attr">d</span>=<span class="hljs-string">&quot;M10 40 l210 0&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">stroke-dasharray</span>=<span class="hljs-string">&quot;20,10,5,5,5,10&quot;</span> <span class="hljs-attr">d</span>=<span class="hljs-string">&quot;M10 60 l210 0&quot;</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">g</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
</code></pre>
<p><img src="https://raw.githubusercontent.com/zhansingsong/svg-tutorials/master/svg%E6%8F%8F%E8%BE%B9%E5%8A%A8%E7%94%BB/imgs/stroke-dasharray.png" alt="stroke-dasharray"></p>
<blockquote>
<p>singsong&#xFF1A;&#x4E5F;&#x5C31;&#x662F;&#x8BF4; <code>stroke-dasharray</code> &#x53D6;&#x503C;&#x6570;&#x5217;&#x4EE5;&#x4E24;&#x4E2A;&#x6570;&#x503C;&#x4E3A;&#x4E00;&#x4E2A;&#x5355;&#x5143;&#x5212;&#x5206;&#xFF0C;&#x6BCF;&#x4E2A;&#x5355;&#x5143;&#x7B2C;&#x4E00;&#x4E2A;&#x503C;&#x8868;&#x793A;dash&#x5927;&#x5C0F;&#xFF0C;&#x7B2C;&#x4E8C;&#x503C;&#x8868;&#x793A;&#x4E24;&#x4E2A;dash&#x4E4B;&#x95F4;&#x7A7A;&#x9699;&#x5927;&#x5C0F;&#x3002;<a href="http://htmlpreview.github.io/?https://github.com/zhansingsong/svg-tutorials/blob/master/svg&#x63CF;&#x8FB9;&#x52A8;&#x753B;/demo/stroke-dasharray.html" target="_blank">&#x6F14;&#x793A;&#x5B9E;&#x4F8B;</a></p>
</blockquote>
<p><img src="https://raw.githubusercontent.com/zhansingsong/svg-tutorials/master/svg%E6%8F%8F%E8%BE%B9%E5%8A%A8%E7%94%BB/imgs/dasharray.gif" alt="dasharray"></p>
</li>
<li><p>stroke-miterlimit&#xFF1A;&#x5F53;<code>stroke-linejoin: miter</code>&#x65F6;&#xFF0C;&#x5BF9; <code>miter</code> &#x8FDB;&#x884C;&#x9650;&#x5236;&#x3002;</p>
</li>
</ul>
<blockquote>
<p>singsong: &#x6837;&#x5F0F;&#x5C5E;&#x6027;&#x4F18;&#x5148;&#x7EA7;&#x4E3A; style &gt; css &gt; attribute&#x3002;</p>
</blockquote>
<h2 id="&#x5982;&#x4F55;&#x8BA9;&#x63CF;&#x8FB9;&#x52A8;&#x8D77;&#x6765;">&#x5982;&#x4F55;&#x8BA9;&#x63CF;&#x8FB9;&#x52A8;&#x8D77;&#x6765;</h2>
<h3 id="stroke-dashoffset">stroke-dashoffset</h3>
<p>&#x8FD9;&#x4E2A;&#x5C5E;&#x6027;&#x7528;&#x4E8E;&#x6307;&#x5B9A; stroke-dasharray &#x5F00;&#x59CB;&#x7684;&#x504F;&#x79FB;&#x91CF;&#x3002;&#x4E5F;&#x662F;&#x672C;&#x6587;&#x91CD;&#x70B9;&#x4ECB;&#x7ECD;&#x5BF9;&#x8C61;&#xFF0C;&#x7406;&#x89E3;&#x8BE5;&#x5C5E;&#x6027;&#x5982;&#x4F55;&#x5DE5;&#x4F5C;&#xFF0C;&#x5C31;&#x80FD;&#x5F88;&#x597D;&#x5730;&#x638C;&#x63E1; svg &#x63CF;&#x8FB9;&#x52A8;&#x753B;&#x3002;stroke-dashoffset &#x53D6;&#x503C;&#x53EF;&#x4EE5;&#x5927;&#x4E8E; 0&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5C0F;&#x4E8E; 0&#x3002;<a href="http://htmlpreview.github.io/?https://github.com/zhansingsong/svg-tutorials/blob/master/svg&#x63CF;&#x8FB9;&#x52A8;&#x753B;/demo/stroke-dashoffset.html" target="_blank">&#x6F14;&#x793A;&#x5B9E;&#x4F8B;</a>&#x3002;</p>
<ul>
<li><p>&#x53D6;&#x503C;&#x5927;&#x4E8E; 0</p>
<p><img src="https://raw.githubusercontent.com/zhansingsong/svg-tutorials/master/svg%E6%8F%8F%E8%BE%B9%E5%8A%A8%E7%94%BB/imgs/dashoffset1.gif" alt="dashoffset1"></p>
</li>
<li><p>&#x53D6;&#x503C;&#x5C0F;&#x4E8E; 0&#x3002;&#x7B49;&#x6548;&#x4E8E;<code>offset = s - |-offset| % s</code>&#x3002;&#x5176;&#x4E2D;<code>offset</code>&#x8868;&#x793A;&#x6B63;&#x53D6;&#x503C;&#xFF0C;<code>s</code>&#x8868;&#x793A;<code>dasharray</code>&#x7684;&#x603B;&#x548C;&#xFF08;&#x5982;&#xFF1A;dasharray: &apos;100 50&apos;&#xFF0C;&#x5219;s: 150&#xFF09;&#x3002;</p>
<p><img src="https://raw.githubusercontent.com/zhansingsong/svg-tutorials/master/svg%E6%8F%8F%E8%BE%B9%E5%8A%A8%E7%94%BB/imgs/dashoffset2.gif" alt="dashoffset2"></p>
</li>
</ul>
<h3 id="&#x52A8;&#x753B;&#x539F;&#x7406;">&#x52A8;&#x753B;&#x539F;&#x7406;</h3>
<p>&#x968F;&#x7740;&#x65F6;&#x95F4;&#x7684;&#x53D8;&#x5316;&#xFF0C;&#x901A;&#x8FC7;&#x63A7;&#x5236; <code>stroke-dashoffset</code> &#x6765;&#x63A7;&#x5236; <code>stroke-dasharray</code> &#x5F00;&#x59CB;&#x7684;&#x504F;&#x79FB;&#x91CF;&#x7684;&#x53D8;&#x5316;&#xFF0C;&#x4EE5;&#x5230;&#x8FBE;&#x52A8;&#x753B;&#x6548;&#x679C;&#x3002;<a href="http://htmlpreview.github.io/?https://github.com/zhansingsong/svg-tutorials/blob/master/svg&#x63CF;&#x8FB9;&#x52A8;&#x753B;/demo/animation_js.html" target="_blank">&#x6F14;&#x793A;&#x5B9E;&#x4F8B;</a>&#x3002;</p>
<blockquote>
<p>singsong&#xFF1A;&#x901A;&#x5E38;&#x4F1A;&#x5C06; <code>stroke-dasharray</code> &#x8BBE;&#x7F6E;&#x4E3A;&#x8DEF;&#x5F84;&#x603B;&#x957F;&#x5EA6;&#x3002;&#x5982;&#x603B;&#x957F;&#x5EA6;&#x4E3A;<code>s</code>&#xFF0C;<code>stroke-dasharray: s</code>&#x6216;<code>stroke-dasharray: s s</code>&#x3002;&#x518D;&#x5C06; <code>stroke-dashoffset</code> &#x53D6;&#x503C;&#x4ECE; <code>s</code> &#x53D8;&#x5316;&#x5230; <code>0</code>&#xFF0C;&#x5C31;&#x53EF;&#x5B9E;&#x73B0;&#x4ECE;&#x65E0;&#x5230;&#x6709;&#x7684;&#x63CF;&#x8FB9;&#x52A8;&#x753B;&#x3002;</p>
</blockquote>
<p><img src="https://raw.githubusercontent.com/zhansingsong/svg-tutorials/master/svg%E6%8F%8F%E8%BE%B9%E5%8A%A8%E7%94%BB/imgs/animation.gif" alt="animation"></p>
<h2 id="&#x52A8;&#x753B;&#x7684;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#xFF1A;&#x6F14;&#x793A;&#x5B9E;&#x4F8B;">&#x52A8;&#x753B;&#x7684;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#xFF1A;<a href="http://htmlpreview.github.io/?https://github.com/zhansingsong/svg-tutorials/blob/master/svg&#x63CF;&#x8FB9;&#x52A8;&#x753B;/demo/animation_demo.html" target="_blank">&#x6F14;&#x793A;&#x5B9E;&#x4F8B;</a></h2>
<ul>
<li>css<pre><code class="lang-css"><span class="hljs-selector-class">.path</span> {
  <span class="hljs-attribute">stroke-dasharray</span>: <span class="hljs-number">523.1047973632812</span>;
  <span class="hljs-attribute">stroke-dashoffset</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">animation</span>: dash <span class="hljs-number">2s</span> linear <span class="hljs-number">3s</span> alternate infinite;
}
@<span class="hljs-keyword">keyframes</span> dash {
    <span class="hljs-selector-tag">from</span> {
        <span class="hljs-attribute">stroke-dashoffset</span>: <span class="hljs-number">523.1047973632812</span>;
    }
    <span class="hljs-selector-tag">to</span> {
        <span class="hljs-attribute">stroke-dashoffset</span>: <span class="hljs-number">0</span>;
    }
}
</code></pre>
</li>
<li><p>js&#x3002;&#x9700;&#x8981;&#x4F7F;&#x7528; <code>SVGGeometryElement.getTotalLength()</code> &#x65B9;&#x6CD5;&#xFF0C;&#x83B7;&#x53D6;&#x8DEF;&#x5F84;&#x7684;&#x603B;&#x957F;&#x5EA6;&#x3002;&#x5728; SVG 1.1 &#x4E2D;&#xFF0C;<code>getTotalLength()</code> &#x53EA;&#x5B58;&#x5728; SVGPathElement &#x4E2D;&#xFF0C;&#x800C;&#x57FA;&#x672C;&#x56FE;&#x5F62;&#x662F;&#x6CA1;&#x6709;&#x8BE5;&#x65B9;&#x6CD5;&#x7684;&#x3002;&#x4E0D;&#x8FC7;&#x5728; SVG 2.0 &#x4E2D;&#xFF0C;&#x57FA;&#x672C;&#x56FE;&#x5F62;&#x4E5F;&#x7EE7;&#x627F;&#x8BE5;&#x65B9;&#x6CD5;&#x3002;<a href="https://stackoverflow.com/questions/26088839/how-do-i-know-if-my-browser-supports-svg-2-0" target="_blank">&#x5982;&#x4F55;&#x68C0;&#x6D4B;SVG&#x7248;&#x672C;&#xFF0C;&#x53EF;&#x4EE5;&#x53C2;&#x8003;&#x8FD9;&#x91CC;&#x3002;</a></p>
<blockquote>
<p>Moved pathLength attribute and <code>getTotalLength()</code> and <code>getPointAtLength()</code> methods from <code>SVGPathElement</code> to <code>SVGGeometryElement</code>&#x3002;&#x2014;&#x2014;&#x2014;&#x2014;<a href="https://developer.mozilla.org/en-US/docs/Web/SVG/SVG_2_support_in_Mozilla" target="_blank">SVG 2 support in Mozilla
</a></p>
</blockquote>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> path = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&apos;.path&apos;</span>);
<span class="hljs-comment">// &#x83B7;&#x53D6;&#x603B;&#x957F;&#x5EA6;</span>
<span class="hljs-keyword">const</span> totalLength = path.getTotalLength();
<span class="hljs-comment">// &#x8BBE;&#x7F6E; stroke-dasharray</span>
path.style.strokeDasharray = totalLength;
<span class="hljs-comment">// &#x8BBE;&#x7F6E; stroke-dashoffset</span>
path.style.strokeDashoffset = totalLength;

<span class="hljs-keyword">let</span> currentFrame = <span class="hljs-number">0</span>;
<span class="hljs-keyword">let</span> totalFrames = <span class="hljs-number">160</span>;
<span class="hljs-keyword">const</span> draw = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">let</span> progress = currentFrame / totalFrames;
    <span class="hljs-keyword">if</span> (progress &gt; <span class="hljs-number">1</span>) {
        <span class="hljs-built_in">window</span>.cancelAnimationFrame(handle);
    } <span class="hljs-keyword">else</span> {
        currentFrame++;
        <span class="hljs-comment">// &#x66F4;&#x65B0; stroke-dashoffset</span>
        path.style.strokeDashoffset = totalLength * (<span class="hljs-number">1</span> - progress);
        handle = <span class="hljs-built_in">window</span>.requestAnimationFrame(draw);
    }
};
draw();
</code></pre>
</li>
</ul>
<h2 id="&#x5B9E;&#x6218;">&#x5B9E;&#x6218;</h2>
<p>&#x5C06; stroke &#x52A8;&#x753B;&#x7528;&#x4E8E;&#x9884;&#x52A0;&#x8F7D;&#x52A8;&#x753B;&#x5C55;&#x793A;</p>
<ul>
<li><p><a href="http://htmlpreview.github.io/?https://github.com/zhansingsong/svg-tutorials/blob/master/svg&#x63CF;&#x8FB9;&#x52A8;&#x753B;/demo/exercise.html" target="_blank">Demo</a></p>
<p><img src="https://raw.githubusercontent.com/zhansingsong/svg-tutorials/master/svg%E6%8F%8F%E8%BE%B9%E5%8A%A8%E7%94%BB/imgs/exercise.gif" alt="exercise"></p>
</li>
<li><p><a href="https://tympanus.net/Development/SVGDrawingAnimation/index.html" target="_blank">&#x5B9E;&#x6218;&#x5B9E;&#x4F8B;</a></p>
<p><img src="https://raw.githubusercontent.com/zhansingsong/svg-tutorials/master/svg%E6%8F%8F%E8%BE%B9%E5%8A%A8%E7%94%BB/imgs/inaction.gif" alt="inaction"></p>
</li>
</ul>
<h2 id="&#x5DE5;&#x5177;">&#x5DE5;&#x5177;</h2>
<ul>
<li><a href="https://vectr.com/" target="_blank">vectr</a>&#xFF1A;SVG &#x5728;&#x7EBF;&#x5236;&#x4F5C;&#x5DE5;&#x5177;&#x2014;&#x2014;<a href="https://dev.to/oppnheimer/you-too-can-animate-svg-line-animation-jgm" target="_blank">Demo</a></li>
<li><a href="https://inkscape.org/" target="_blank">INKSCAPE</a>&#xFF1A;SVG &#x5236;&#x4F5C;&#x5DE5;&#x5177;</li>
<li><a href="https://jakearchibald.github.io/svgomg/" target="_blank">SVGOMG</a>: SVG &#x538B;&#x7F29;&#x5DE5;&#x5177;</li>
</ul>
<h2 id="&#x76F8;&#x5173;&#x5E93;">&#x76F8;&#x5173;&#x5E93;</h2>
<ul>
<li><a href="http://maxwellito.github.io/vivus/" target="_blank">vivus</a></li>
<li><a href="https://github.com/camoconnell/lazy-line-painter" target="_blank">Lazy Line Painter</a></li>
<li><a href="https://github.com/ConnorAtherton/walkway" target="_blank">Walkway</a> &#x2014;&#x2014; <a href="https://www.polygon.com/a/ps4-review" target="_blank">Demo</a></li>
</ul>
<h2 id="&#x53C2;&#x8003;&#x6587;&#x7AE0;">&#x53C2;&#x8003;&#x6587;&#x7AE0;</h2>
<ul>
<li><a href="https://css-tricks.com/svg-line-animation-works/" target="_blank">How SVG Line Animation Works</a></li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../svg之path/svg之path.html" class="navigation navigation-prev " aria-label="Previous page: svg 之 path">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../svg之fill及fill-rule/svg之fill及fill-rule.html" class="navigation navigation-next " aria-label="Next page: svg 之 fill 及 fill-rule">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"svg 描边动画","level":"1.5","depth":1,"next":{"title":"svg 之 fill 及 fill-rule","level":"1.6","depth":1,"path":"svg之fill及fill-rule/svg之fill及fill-rule.md","ref":"./svg之fill及fill-rule/svg之fill及fill-rule.md","articles":[]},"previous":{"title":"svg 之 path","level":"1.4","depth":1,"path":"svg之path/svg之path.md","ref":"./svg之path/svg之path.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"svg描边动画/svg描边动画.md","mtime":"2019-09-20T06:30:25.638Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-10-21T06:03:10.264Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

